    vector<int> v1;
    vector<int> v2;
    //存入叶子节点
    void push_leaf(TreeNode* root, vector<int>& v)
    {
        if(!root)
            return;
        if(root->left==nullptr&&root->right==nullptr)
            v.push_back(root->val);
       
        push_leaf(root->left,v);
        push_leaf(root->right,v);
    }

    bool leafSimilar(TreeNode* root1, TreeNode* root2)
    {
        push_leaf(root1,v1);
        push_leaf(root2,v2);
        if(v1.size()!=v2.size())
            return false;
        int len=v1.size();
        //从v1的首和v2的尾进行判断
        for(int i=0;i<v1.size();i++)
        {      
            if(v1[i]!=v2[--len])
                return false;             
        }
        return true;
    }